package com.daka.service.impl;

import com.daka.dao.IndexDataMapper;
import com.daka.dao.TopicCommentMapper;
import com.daka.dao.TopicMapper;
import com.daka.entity.IndexData;
import com.daka.entity.Topic;
import com.daka.enumerate.TopicEnum;
import com.daka.service.IndexDataService;
import com.daka.service.TopicService;
import com.daka.vo.db.TopicCommentVolunteerVo;
import com.daka.vo.request.TopicListRequestVo;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.Calendar;
import java.util.Date;
import java.util.List;

/**
 * @author beliveli on 2016/3/31 0031.
 */
@Service("indexDataService")
@SuppressWarnings("unused")
public class IndexDataServiceImpl implements IndexDataService {

    @Resource
    private IndexDataMapper indexDataMapper;

    public IndexData selectById(int id) {
        return indexDataMapper.selectById(id);
    }

    public List<IndexData> selectAll() {
        return indexDataMapper.selectAll();
    }

    public IndexData save(IndexData indexData) {

        int resultCount;
        if (null == indexData.getId() || indexData.getId() == 0) {
            Date thisData = new Date();
            indexData.setCreateTime(thisData);

            Calendar calendar= Calendar.getInstance();
            calendar.setTime(thisData);
            calendar.add(Calendar.DATE, 1);
            indexData.setStopTime(calendar.getTime());

            indexData.setDelStatus(0);
            indexData.setDisplay(1);
            indexData.setTop(1);
            indexData.setStopStatus(1);

            resultCount = indexDataMapper.save(indexData);
        } else {
//            resultCount = topicMapper.updateById(topic);
        }

//        if (resultCount == 0) {
//            return null;
//        }
        return indexData;
    }

    public int updateDelStatus(Integer status,Integer topicId,Integer groupId,Integer activityId){
        return indexDataMapper.updateDelStatus(status,topicId, groupId, activityId);
    }
}
